<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #img {
            width: 500px;
            margin: 0 auto;
            height: 400px;
            position: relative;
        }
        
        #img img {
            width: 500px;
            height: 400px;
            position: absolute;
            opacity: 0;
        }
        
        #img img:first-child {
            opacity: 1;
        }
        /* img:nth-child(1) {
            opacity: 1;
        } */
        
        ul {
            position: absolute;
            list-style: none;
            width: 200px;
            bottom: 10px;
            left: 0;
            right: 0;
            margin: auto;
        }
        
        li {
            float: left;
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background-color: rgba(154, 117, 255, 0.637);
            line-height: 30px;
            text-align: center;
            margin: 0 5px;
        }
    </style>
</head>

<body>
    <div id="img">
        <img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2848120264,2778704476&fm=26&gp=0.jpg" alt="">
        <img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3712714479,3065695217&fm=26&gp=0.jpg" alt="">
        <img src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3319074242,804368993&fm=26&gp=0.jpg" alt="">
        <img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1208682799,4078852213&fm=26&gp=0.jpg" alt="">
        <img src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1175179067,2902739431&fm=26&gp=0.jpg" alt="">
        <ul id="ul">
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
    </div>


</body>

</html>
<script>
    var img = document.getElementsByTagName('img');
    var ul = document.getElementsByTagName('li');
    console.log(ul);
    console.log(img);
    var indx = 0;

    for (var i = 0; i < 5; i++) {
        // ul[i].onclick = function() {
        ul[i].onclick = function() {
//      	console.log(this);
            for (var j = 0; j < 5; j++) {
                if (this == ul[j]) {
                    indx = j;
                    // console.log(j);
                }
            }
            for (var k = 0; k < 5; k++) {
                if (k == indx) {
                    // console.log(k);
                    img[k].style.opacity = 1;
                } else {
                    img[k].style.opacity = 0;
                }
            }
        }
    }
</script>